********************************************************************************
***************************** Main Results *************************************
********************************************************************************
use data_final_for_analysis, clear

global ctrls c_*
global regime r_*
global capacity cp_*
global leader ld_*

**# Table 1: Pandemic Performance: Cases \& Deaths
eststo clear
// Cases per million //
reghdfe log_case_cumtotal_per1m stdtr if cross_samp==1, a(ht_region) vce(robust)
quietly estadd local fixedm "Yes", replace
est store m1

reghdfe log_case_cumtotal_per1m stdtr $ctrls if cross_samp==1, a(ht_region) vce(robust)
quietly estadd local fixedm "Yes", replace
quietly estadd local EDCov "Yes", replace
est store m2

reghdfe log_case_cumtotal_per1m stdtr $regime $capacity $leader $ctrls if cross_samp==1, a(ht_region) vce(robust)
quietly estadd local fixedm "Yes", replace
quietly estadd local EDCov "Yes", replace
est store m3

dsregress log_case_cumtotal_per1m stdtr if cross_samp==1, controls((i.ht_region) $regime $capacity $leader $ctrls) selection(cv) vce(robust) rseed(12345)
quietly estadd local fixedm "Yes", replace
quietly estadd local EDCov "Yes", replace
est store m4

// LASSO selection results //
estimates store ds_cv
lassocoef(ds_cv, for (stdtr))

// Deaths per million //
reghdfe log_death_cumtotal_per1m stdtr if cross_samp==1, a(ht_region) vce(robust)
quietly estadd local fixedm "Yes", replace
est store m5

reghdfe log_death_cumtotal_per1m stdtr $ctrls if cross_samp==1, a(ht_region) vce(robust)
quietly estadd local fixedm "Yes", replace
quietly estadd local EDCov "Yes", replace
est store m6

reghdfe log_death_cumtotal_per1m stdtr $regime $capacity $leader $ctrls if cross_samp==1, a(ht_region) vce(robust)
quietly estadd local fixedm "Yes", replace
quietly estadd local EDCov "Yes", replace
est store m7

dsregress log_death_cumtotal_per1m stdtr if cross_samp==1, controls((i.ht_region) $regime $capacity $leader $ctrls) selection(cv) vce(robust) rseed(12345)
quietly estadd local fixedm "Yes", replace
quietly estadd local EDCov "Yes", replace
est store m8

// LASSO selection results //
estimates store ds_cv
lassocoef(ds_cv, for (stdtr))

esttab m1 m2 m3 m4 m5 m6 m7 m8 using Table_1.rtf, replace ///
title("Pandemic Performance: Cases & Deaths") ///
mgroups("Cases" "Deaths", pattern(1 0 0 0 1)) ///
b(3) se(3) nonote nocons nobaselevels nodepvars ar2 ///
order(stdtr $regime $capacity ld_leaderage ld_female ld_length_ce ld_college ld_major_n_3 ld_major_n_4 ld_major_n_5 ld_TBI) ///
drop($ctrls _cons) nogaps ///
label s(EDCov fixedm N r2_a, label("Geog & Socioecon. Covariates" "Regional FE" "Observations" "Adjusted R{\super 2}") fmt(0 0 0 3)) ///
compress nomtitles starlevels(* .1 ** 0.05 *** 0.01)

********************************************************************************
****************************** Subgroup Analysis *******************************
********************************************************************************
use data_final_for_analysis, clear

**# Table 2: Subgroup Results by Regime and Income Level
eststo clear

*Regime type
reghdfe log_case_cumtotal_per1m stdtr $regime $capacity $leader $ctrls if cross_samp==1 & v2x_regime<2, a(ht_region) vce(robust)
quietly estadd local fixedm "Yes", replace
quietly estadd local Cov "Yes", replace
est store m1

reghdfe log_case_cumtotal_per1m stdtr $regime $capacity $leader $ctrls if cross_samp==1 & v2x_regime>1, a(ht_region) vce(robust)
quietly estadd local fixedm "Yes", replace
quietly estadd local Cov "Yes", replace
est store m2

reghdfe log_death_cumtotal_per1m stdtr $regime $capacity $leader $ctrls if cross_samp==1 & v2x_regime<2, a(ht_region) vce(robust)
quietly estadd local fixedm "Yes", replace
quietly estadd local Cov "Yes", replace
est store m3

reghdfe log_death_cumtotal_per1m stdtr $regime $capacity $leader $ctrls if cross_samp==1 & v2x_regime>1, a(ht_region) vce(robust)
quietly estadd local fixedm "Yes", replace
quietly estadd local Cov "Yes", replace
est store m4

*GDP per capita $10000
reghdfe log_case_cumtotal_per1m stdtr $regime $capacity $leader $ctrls if cross_samp==1 & gdpp>10000, a(ht_region) vce(robust)
quietly estadd local fixedm "Yes", replace
quietly estadd local Cov "Yes", replace
est store m5

reghdfe log_death_cumtotal_per1m stdtr $regime $capacity $leader $ctrls if cross_samp==1 & gdpp>10000, a(ht_region) vce(robust)
quietly estadd local fixedm "Yes", replace
quietly estadd local Cov "Yes", replace
est store m6

reghdfe log_case_cumtotal_per1m stdtr $regime $capacity $leader $ctrls if cross_samp==1 & gdpp<10000, a(ht_region) vce(robust)
quietly estadd local fixedm "Yes", replace
quietly estadd local Cov "Yes", replace
est store m7

reghdfe log_death_cumtotal_per1m stdtr $regime $capacity $leader $ctrls if cross_samp==1 & gdpp<10000, a(ht_region) vce(robust)
quietly estadd local fixedm "Yes", replace
quietly estadd local Cov "Yes", replace
est store m8

esttab m1 m3 m2 m4 m5 m6 m7 m8 using Table_2.rtf, replace ///
title("Subgroup Results by Regime and Income Level") ///
mgroups("Autocratic Regime" "Democratic Regime" "Higher Income" "Lower Income", pattern(1 0 1 0 1 0 1 0)) ///
b(3) se(3) nonote nocons nobaselevels nodepvars ar2 ///
mtitles("Cases" "Deaths" "Cases" "Deaths" "Cases" "Deaths" "Cases" "Deaths") ///
keep(stdtr) ///
label s (Cov fixedm N r2_a, label("Covariates" "Regional FE" "Observations" "Adjusted R{\super 2}") fmt(0 0 0 3)) ///
compress noomit starlevels(* .1 ** 0.05 *** 0.01) 

********************************************************************************
****************************** Mechanism ***************************************
********************************************************************************
use data_final_for_analysis, clear

merge 1:1 date ccodealp using data_mechanism

encode ccodealp, gen(cid)

*Moving average
xtset cid TSEdate

tssmooth ma mean_case_14d=new_cases_per_million if new_cases_per_million>=0, window(14)
gen log_mean_case_14d=log(mean_case_14d + 1)

tssmooth ma mean_death_14d=new_deaths_per_million if new_deaths_per_million>=0, window(14)
gen log_mean_death_14d=log(mean_death_14d + 1)

gen mask_w_per = mask_w 
gen log_mask_w_per = log(mask_w_per + 1)

*lag effects
bysort cid: gen Lag3_face=facialcovering[_n-3]

label variable stdtr "Political Trust"
label variable log_mean_case_14d "New Cases (Log, Past 14 Ds)"
label variable log_mean_death_14d "New Deaths (Log, Past 14 Ds)"
label variable facialcovering "Face Covering Requirements"
label variable Lag3_face "Face Covering Requirements (Lag 3 Ds)"

**# Table 3: Mechanism: Policy Compliance Effects
eststo clear

reghdfe log_mask_w_per (c.facialcovering)##(c.stdtr), a(cid TSEdate) cluster(cid)
quietly estadd local CDFE "Yes", replace
est store m1

reghdfe log_mask_w_per (c.facialcovering)##(c.stdtr) c.log_mean_case_14d, a(cid TSEdate) cluster(cid)
quietly estadd local NewCase "Yes", replace
quietly estadd local CDFE "Yes", replace
est store m2

reghdfe log_mask_w_per (c.Lag3_face)##(c.stdtr) c.log_mean_case_14d, a(cid TSEdate) cluster(cid)
quietly estadd local NewCase "Yes", replace
quietly estadd local CDFE "Yes", replace
est store m3

esttab m1 m2 m3 using Table_3.rtf, replace ///
title("Mechanism: Policy Compliance Effect") ///
b(3) se(3) nonote nocons nobaselevels nodepvars nogaps ar2 ///
order(facialcovering c.facialcovering#c.stdtr Lag3_face c.Lag3_face#c.stdtr) drop(_cons stdtr log_mean_case_14d) ///
label interaction(" x ") s(NewCase CDFE N r2_a, label("New Cases (Past 14 Ds)" "Country & Time FE" "Observations" "Adjusted R{\super 2}") fmt(0 0 0 3)) ///
compress nomtitles starlevels(* .1 ** 0.05 *** 0.01)

********************************************************************************
******************* Government Policy Response *********************************
********************************************************************************
eststo clear

eststo m1: reghdfe school (c.log_mean_case_14d)##(c.stdtr), a(cid TSEdate) cluster(cid)
quietly estadd local CDFE "Yes", replace

eststo m2: reghdfe workplace (c.log_mean_case_14d)##(c.stdtr), a(cid TSEdate) cluster(cid)
quietly estadd local CDFE "Yes", replace

eststo m3: reghdfe gathering (c.log_mean_case_14d)##(c.stdtr), a(cid TSEdate) cluster(cid)
quietly estadd local CDFE "Yes", replace

eststo m4: reghdfe stayathome (c.log_mean_case_14d)##(c.stdtr), a(cid TSEdate) cluster(cid)
quietly estadd local CDFE "Yes", replace

**# Table 4: Mechanism: Policy Discretion Effect (Panel A: New Cases)
esttab m1 m2 m3 m4 using Table_4_1.rtf, replace ///
title("Panel A: New Cases") ///
mgroups("School Closure" "Workplace Closure" "Gathering Restrictions" "Stay at Home", pattern(1 1 1 1)) ///
b(3) se(3) nonote nocons nobaselevels nodepvars ar2 ///
order(log_mean_case_14d c.log_mean_case_14d#c.stdtr) drop(_cons stdtr) ///
label s(CDFE N r2_a, label("Country & Time FE" "Observations" "Adjusted R{\super 2}") fmt(0 0 3 0)) ///
compress nomtitles starlevels(* .1 ** 0.05 *** 0.01) interaction(" x ") 

eststo clear

eststo m1: reghdfe school (c.log_mean_death_14d)##(c.stdtr), a(cid TSEdate) cluster(cid)
quietly estadd local CDFE "Yes", replace

eststo m2: reghdfe workplace (c.log_mean_death_14d)##(c.stdtr), a(cid TSEdate) cluster(cid)
quietly estadd local CDFE "Yes", replace

eststo m3: reghdfe gathering (c.log_mean_death_14d)##(c.stdtr), a(cid TSEdate) cluster(cid)
quietly estadd local CDFE "Yes", replace

eststo m4: reghdfe stayathome (c.log_mean_death_14d)##(c.stdtr), a(cid TSEdate) cluster(cid)
quietly estadd local CDFE "Yes", replace

**# Table 4: Mechanism: Policy Discretion Effect (Panel B: New Deaths)
esttab m1 m2 m3 m4 using Table_4_2.rtf, replace ///
title("Panel B: New Deaths") ///
mgroups("School Closure" "Workplace Closure" "Gathering Restrictions" "Stay at Home", pattern(1 1 1 1)) ///
b(3) se(3) nonote nocons nobaselevels nodepvars nogaps ar2 ///
order(log_mean_death_14d c.log_mean_death_14d#c.stdtr) drop(_cons stdtr) ///
label s(CDFE N r2_a, label("Country & Time FE" "Observations" "Adjusted R{\super 2}") fmt(0 0 3 0)) ///
compress nomtitles starlevels(* .1 ** 0.05 *** 0.01) interaction(" x ") 